<?

#print_r($_REQUEST);

/* 
 * View implementation for the DefaultView controller
 */ 

$zoneDS = DB_GetDataset('zones', getDefault($this->character->charDS['c_location'], 1));
if ($this->user->localRecord['u_showads'] == 'Y' && $config['enableads'])
{
?>
<div style="position: absolute; right: 0px; top: 108px; width: 468px; height: 60px;">
  <span style="color: gray"><b>Ad: </b>(<a href="?ads=hide" <?= ToolTip(':hide all ads') ?>>click here if you hate it</a>)</span>
  <iframe frameborder='no' scrolling='no' width='468' height='60' style='overflow: hidden;' src='http://www.fbexchange.com/getLink.php?prodId=92527&style=2&bg=fff&link=3b5998&border=ccc'></iframe>
</div>
<?
}

if ($this->banner != '')
  print('<div class="banner">'.$this->banner.'</div><br/>');

?>
Welcome, <?= $this->character->charDS['c_name'] ?>, to 

<h2>Popsickles of Nerdia</h2>
<b>The Geek, the Grue and the Lolcat</b>
<p/><p/>
<table width="100%">
<tr><td valign="top">
  <?
  if(sizeof($this->invitations)>0)
  {
  ?><div class="banner">
  <h3 style="margin: 0px; padding: 0px;">Adventuring Invitations</h3>
  <table>
  <?
  foreach($this->invitations as $inv)
  {
  $lastname = $inv['u_fb_name'];
  $firstname = CutSegment(' ', $lastname);
  ?>
    <tr>
      <td width="40"><img src="<?= getDefault($inv['u_fb_pic_square'], $config['friend.stdimage']) ?>"/></td>
      <td valign="top">
        <?= $inv['u_fb_name'] ?> has invited you to join their party!<br/>
        <input type="button" name="join" value="Team up with <?= $firstname ?>!" 
          onclick="document.location.replace('<?= actionUrl('join', 'party', 'party='.$inv['u_key']) ?>');"/>
        <input type="button" name="join" value="Ignore"
          onclick="document.location.replace('<?= actionUrl('ignore', 'party', 'party='.$inv['u_key']) ?>');"/>
      </td>
    </tr>
  <?
  }
  ?>
  </table></div><br/>
  <?
  }
  $duelNews = DB_GetList('SELECT h_key,h_character,h_type,h_count,h_mob,c_key,c_name,c_level FROM '.getTableName('history').'
    LEFT JOIN '.getTableName('characters').' ON (h_mob=c_key)
    WHERE 
      (h_character="'.$this->character->charDS['c_key'].'") AND
      (h_type="duelv" OR h_type="dueld")
    ORDER BY h_last DESC
    LIMIT 5');
  foreach($duelNews as $duel)
  {
    $temp = $duel['c_name'];
    $firstName = CutSegment(' ', $temp);
    ?><div><?
    if ($duel['h_type'] == 'duelv')
      print('You won '.$duel['h_count'].' '.makePlural('duel', $duel['h_count']).' against ');
    else 
      print('You were defeated '.$duel['h_count'].' '.makePlural('time', $duel['h_count']).' by ');
    print('<b><a href="'.actionUrl('view', 'character', 'id='.$duel['c_key']).'">'.$duel['c_name'].'</a></b>, level '.$duel['c_level']);
    if ($this->character->level < $duel['c_level']+3)
      print(': <b><a href="'.actionUrl('attack', 'duel', 'id='.$duel['c_key']).'">challenge '.$firstName.'!</a></b>');
    ?></div><?
  }
  if (sizeof($duelNews)>0) print('<br/>');
  ?>
  <h3 style="margin: 0px">And now what?</h3>
  <table width="500">
    <tr>
      <td valign="top" width="64"><a href="<?= actionUrl('index', 'game') ?>"><img src="img/zones/<?= $zoneDS['z_icon'] ?>.png" 
        style="background: #ffffff; border: 1px solid gray;" width="64"/></a></td>
      <td>
        Your current location is: <b><a href="<?= actionUrl('index', 'game') ?>"><?= $zoneDS['z_name'] ?></a></b>.<br/>
        Click on "Action" in the menu above to continue your adventure! 
        Or, if you're feeling aggressive, you can <b><a href="<?= actionUrl('index', 'duel') ?>">
          challenge a stranger to a duel!</a></b>
      </td>
      <td valign="top" width="64"></td>
    </tr>
    <tr>
      <td valign="top" width="64"></td>
      <td>
        Your character, aptly named <b><?= $this->character->charDS['c_name'] ?></b>,<br/>
        is at <b><a href="<?= actionUrl('index', 'character') ?>">level <?= $this->character->charDS['c_level'] ?></a></b> in the game.
        Click on "Character" in the menu above to see your stats!<br/>
        <br/>
        <b><a href="<?= actionUrl('history', 'character') ?>">Click here to see what you already accomplished.</a></b>
      </td>
      <td valign="top" width="64"><img src="img/human.png" 
        style="background: #ffffff; border: 1px solid gray;" width="64"/></td>
    </tr>
    <tr>
      <td valign="top" width="64"><img src="img/thug.png" 
        style="background: #ffffff; border: 1px solid gray;" width="64"/></td>
      <td>
        <? 
        if ($this->partyCount == 1)
          print('Your adventuring party has <b><a href="'.actionUrl('index', 'party').'">one member</a></b>. '); 
        else
          print('Your adventuring party has <b><a href="'.actionUrl('index', 'party').'">'.$this->partyCount.' members.</a></b>. ');
          
        $cTeamList = DB_GetList('SELECT p_key,c_name,c_key FROM '.getTableName('parties').' 
          LEFT JOIN '.getTableName('characters').' ON (c_ref_user=p_party)
          WHERE p_member="'.$this->character->charDS['c_ref_user'].'"
          ORDER BY c_level
          ');
        if (sizeof($cTeamList)>0)
        {
          $ctl = array();
          foreach($cTeamList as $cds) $ctl[] = '<a style="font-weight: bold;" href="'.actionUrl('view', 'character', 'id='.$cds['c_key']).'">'.$cds['c_name'].'</a>';
          print('Your friends '.implode(', ', $ctl).' each have chosen you for their COmbat Teams.');
        }
        ?><br/>
        <br/>
        You also have <a style="font-weight: bold;" href="<?= actionUrl('cheat', 'meta') ?>">
        <?= $this->user->localRecord['u_cheatpoints'].' '.makePlural('Cheat Points', $this->user->localRecord['u_cheatpoints']) ?>.
        Click here</a> to see how you can make your character better by spending some.
        You get 3 Cheat Points each for the first 10 party members you successfully
        invite to your group!
      </td>
      <td valign="top" width="64"></td>
    </tr>
    <tr>
      <td valign="top" width="64">&nbsp;</td>
      <td>
        This application will never send any messages to
        your friends without your expressed permission, nor will it spam
        your profile with feed messages. If you like it, <b><a href="<?= actionUrl('invite', 'party') ?>">
        invite some people</a></b> who you think might enjoy the game.<br/>
        <br/>
        If you want to show support, consider becoming a fan of
        <b><a target="_top" href="http://www.facebook.com/apps/application.php?id=8647737028">Nerdia's about page</a></b> and
        befriend the <b><a href="http://www.facebook.com/profile.php?id=597325803">Awesome Creator</a></b> :-)
      </td>
      <td valign="top" width="64"><img src="img/heart.png" 
        style="background: #ffffff; border: 1px solid gray;" width="64"/></td>
    </tr>
  </table>
</td><td width="24"></td><td valign="top" width="*">
<h3 style="margin: 0px">Recent Changes</h3>
<ul style="padding: 0px; margin: 0px; padding-left: 12px;">
  <li>Layout optimizations on the Action, Shop and Character screens</li>
  <li>Map-type levels now use AJAX, should be way snappier and more fun!</li>
  <li>You can now talk to some creatures!</li>
  <li>"Do this again" button after fights</li>
  <li>Less scroll bars everywhere!</li>
</ul>
<br/>
<h3 style="margin: 0px">News</h3>
<?
foreach($this->news as $nds)
{
  ?><h4><?= $nds['n_title'] ?></h4>
  <div><?= nl2br($nds['n_content']) ?></div>
  <div align="right" style="padding-top: 3px"><a class="linkbutton" href="<?= actionUrl('news', 'meta', 'id='.$nds['n_key']) ?>">comments</a></div><br/><?
}
?>
</td></tr></table>
